package cn.com.egova.skinapplication;

import android.content.Intent;
import android.os.Bundle;
import android.os.Environment;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import java.io.File;

import cn.com.egova.skinapplication.skin.SkinManager;
import cn.com.egova.skinapplication.skin.base.BaseSkinActivity;
import cn.com.egova.skinapplication.skin.callback.ISkinChangingCallback;

public class MainActivity extends BaseSkinActivity {
    public static final String APK_SDCARD_PATH = "demo/Skin.apk";
    private TextView tv;
    private ImageView iv;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        tv = (TextView) findViewById(R.id.tv);
        iv = (ImageView) findViewById(R.id.iv);
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.menu_main,menu);
        return true;
    }


    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        int id = item.getItemId();

        String skinPluginPath = Environment.getExternalStorageDirectory() + File.separator+APK_SDCARD_PATH;
        String skinPluginPkg = "com.example.skin";
        switch (id) {
            case  R.id.action_changeSkin: //插件式换肤
                SkinManager.getInstance().changeSkin(skinPluginPath,skinPluginPkg, new ISkinChangingCallback() {
                    @Override
                    public void onStart() {

                    }

                    @Override
                    public void onRepeat() {
                        Toast.makeText(MainActivity.this,"换肤重复",Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onError() {
                        Toast.makeText(MainActivity.this,"换肤失败",Toast.LENGTH_SHORT).show();
                    }

                    @Override
                    public void onComplete() {
                        Toast.makeText(MainActivity.this,"换肤成功",Toast.LENGTH_SHORT).show();
                    }
                });
                break;

            case  R.id.action_changeSkinApp: //应用内换肤
                SkinManager.getInstance().changeSkin("_app");
                break;

            case  R.id.action_reset:
                SkinManager.getInstance().changeSkin(""); //走的还是应用内换肤,用的是原来的资源.
                break;
            case  R.id.action_testFactory:
                startActivity(new Intent(this,TestFactoryActivity.class));
                break;
        }
        return super.onOptionsItemSelected(item);
    }

}
